home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-07-25 | 39.3 KB | 1,685 lines | [TEXT/PJMM] |
- { ******************************************************** }
- { "wBarMenu.p" }
- { }
- { by: }
- { James Matthews }
- { < MacTutor -- Nov 88 > }
- { }
- { with color + hierarchial Menu support }
- { and other nifty additions by: }
- { John A. Love, III }
- { [ Washington Apple Pi Users' Group] }
- { }
- { using Symantec's "THINK Lightspeed Pascal", v 3.02 }
- { }
- { ******************************************************** }
-
-
-
-
- PROGRAM wBarMenu;
-
- {$I-}
-
- USES
- Types, Memory, OSUtils, Quickdraw, Events, Files, AppleTalk, PPCToolbox, Processes, EPPC, Notification, AppleEvents, AERegistry, Script, Packages, Dialogs, CTBUtilities, Connections, Menus, TextEdit, Traps, Balloons, wBMGlobals, wBMMiscSubs, OffScreenSubs, wBMScrollSubs, wBarMenuProc, wBMBalloons, wBMWindSubs, myAppleEvents;
-
-
-
-
- { ----------------------- }
- { Guess what this does ?? }
- { ----------------------- }
-
- PROCEDURE HandleCursor;
-
- VAR
- PlusCurs, TECurs: CursHandle;
- mouse: Point;
- rightSB, bottomSB: Rect;
-
-
- BEGIN
-
- IF currDA | NOT myAppl THEN
- EXIT(HandleCursor); { DAs & other applications roll their own }
-
- WITH FW^ DO
- BEGIN
-
- GetMouse(mouse);
- ;
- IF applWind THEN
- BEGIN
- InWindow := PtInRect(mouse, portRect);
- GetWBMrects(FW, WBMrect, leftMSArect, rightMSArect);
- IF NOT EmptyRect(WBMrect) THEN
- InWBMenu := PtInRect(mouse, WBMrect)
- ELSE
- InWBMenu := FALSE; { NO Window Bar Menu. }
- END
- ELSE { Zip windows or a DA is up }
- InWindow := FALSE; { By definition, InWBMenu := FALSE. }
-
- IF NOT InWindow THEN
- InitCursor
-
- ELSE
- BEGIN
-
- IF InWBMenu THEN
- InitCursor { Cursor in Window Bar Menu. }
-
- ELSE IF (windType = rDocProc) THEN { My startup "rDocProc" window. }
- BEGIN
- PlusCurs := GetCursor(plusCursor);
- SetCursor(PlusCurs^^);
- END
-
- ELSE { In Scroll Bars or not ??? }
-
- BEGIN
- rightSB := portRect;
- bottomSB := portRect;
- IF hasGrowIcon THEN
- BEGIN
- WITH rightSB DO
- left := right - (scrollWidth - frame);
- WITH bottomSB DO
- top := bottom - (scrollHeight - frame);
- END;
-
- IF PtInRect(mouse, rightSB) | PtInRect(mouse, bottomSB) THEN
- InitCursor
- ELSE
- BEGIN
- TECurs := GetCursor(iBeamCursor);
- SetCursor(TECurs^^);
- END;
- END; { InWindow, NOT InWBMenu, zoomDocProc window }
-
- END; { IF InWindow }
-
- END; { WITH }
-
- END; { HandleCursor }
-
-
-
- { ----------------------------------------------------------------- }
- { PeriodicMenus is called before action is taken on menu commands }
- { to correctly enable or disable the "Edit" Menu in case a Desk }
- { Accessory owns the front window or no window is up, respectively. }
- { The latter also affects individual items in the other Menu(s). }
- { ----------------------------------------------------------------- }
-
- PROCEDURE PeriodicMenus;
-
- CONST
- wholeMenu = 0;
-
- VAR
- daWind: BOOLEAN;
- redraw: BOOLEAN; { Used to avoid a flickering MenuBar. }
-
-
- PROCEDURE SetEnable (menu: MenuHandle; item: INTEGER; tobeEnabled: BOOLEAN);
- { --------------------- }
- { To be or not to be !! }
- { --------------------- }
-
- BEGIN
- IF tobeEnabled THEN
- EnableItem(menu, item)
- ELSE
- DisableItem(menu, item);
- END; { SetEnable }
-
-
- FUNCTION daMenu: BOOLEAN;
- { I know ... NEVER assume knowledge of Menu Record structures ... BUT ... }
-
- CONST
- MenuListLoc = $A1C;
-
- TYPE
- rMenuRec = RECORD
- menuOH: MenuHandle;
- menuLeft: INTEGER; { Left edge of Menu. }
- END; { rMenuRec }
-
- hMenuRec = RECORD
- menuHOH: MenuHandle;
- reserved: INTEGER;
- END; { hMenuRec }
-
- MenuList = RECORD
- lastMenu: INTEGER; { Offset to last regular MenuHandle. }
- lastRight: INTEGER; { Right edge of last Menu's title. }
- mbResID: INTEGER;
- rMenu: ARRAY[0..0] OF rMenuRec;
- { The following fields are also present: }
- { }
- { lastHMenu: INTEGER; -- Offset from here to last hierarchical Menu. }
- { menuTitleSave: PixMapHandle; }
- { hMenu: ARRAY[0..0] OF hMenuRec; -- When my daMenu routine is called, }
- { there are NO hierarchical Menus. }
- END; { MenuList }
-
- MenuListPtr = ^MenuList;
- MenuListHdl = ^MenuListPtr;
-
- VAR
- MLHdl: MenuListHdl;
- nbrMenusX6, menuCounter, theMenuID: INTEGER;
-
-
- BEGIN
-
- MLHdl := MenuListHdl(longPtr(MenuListLoc)^);
- nbrMenusX6 := ORD(MLHdl^^.lastMenu);
- menuCounter := (nbrMenusX6 DIV 6) - 1;
-
- WHILE menuCounter >= 0 DO
- BEGIN
- theMenuID := MLHdl^^.rMenu[menuCounter].menuOH^^.menuID;
- { Watch out !!! with System 7 ... }
- { ... the Help Menu (kHMHelpMenuID = -16490) & }
- { ... the Application Menu (ID = ???) }
- IF (theMenuID < 0) & (theMenuID >= -16384) THEN
- Leave;
- menuCounter := menuCounter - 1;
- END; { scanning the MenuBar }
-
- { I could have used: }
- { daMenu := theMenuID < 0; }
- { because I KNOW my app has menus. However, to make this routine }
- { applicable to ANY app, what if ANY app had zip menus and there }
- { were no DA menus, then I would have to initialize with: }
- { theMenuID := 0; }
- { putting an extra statement in a time-critical "doPeriodic" loop. }
- daMenu := menuCounter >= 0;
-
- END; { daMenu }
-
-
- BEGIN { PeriodicMenus }
-
- redraw := FALSE;
- FW := FrontWindow; { Used by HandleCursor ... }
- daWind := (FW <> NIL) & (WindowPeek(FW)^.windowKind < 0);
- currDA := daWind | daMenu; { = FALSE if another application }
- { under MultiFinder. }
- applWind := (FW <> NIL) & NOT currDA; { = TRUE if ... }
-
- SetEnable(FileMenu, NewWindowItem, NOT currDA & moreNew);
- SetEnable(FileMenu, CloseWindowItem, myAppl & applWind);
- { Item = "Next window":}
- SetEnable(WindowMenu, firstWindowItem - 2, windowCount > 1);
-
- IF (currDA <> prevDA) | (applWind <> prevWind) THEN
- BEGIN
- SetEnable(EditMenu, wholeMenu, daWind | applWind);
- SetEnable(WindowMenu, wholeMenu, applWind);
- redraw := TRUE;
- END;
-
- prevDA := currDA;
- prevWind := applWind;
-
- IF redraw THEN
- DrawMenuBar;
-
- END; { PeriodicMenus }
-
-
-
- { ----------- }
- { Bye-Bye !! }
- { ----------- }
-
- PROCEDURE DoQuit;
-
- BEGIN
-
- DoCloseAll;
- DisposHandle(Handle(mBarList));
- HUnlock(Handle(windowStorage));
- DisposHandle(Handle(windowStorage));
- ;
- Done := TRUE;
-
- END; { DoQuit }
-
-
-
- PROCEDURE DrawContents (window: WindowPtr);
-
- VAR
- savedTEH: TEHandle;
-
-
- BEGIN
-
- EraseRect(window^.portRect);
- savedTEH := textH;
- textH := TEHandle(GetWRefCon(window));
- IF textH <> NIL THEN
- TEUpdate(window^.portRect, textH);
- textH := savedTEH;
- mBar := wGetMenuBar(window);
- IF mBar <> NIL THEN
- BEGIN
- wDrawMSA(mBar); { Calls GetWBMrects. }
- wDrawMenuBar(mBar);
- END; { window has a WBM }
- DrawControls(window);
- IF hasGrowIcon THEN
- DrawGrowIcon(window);
-
- END; { DrawContents }
-
-
-
- { ==================================================== }
- { HandleUpdate re-draws any controls, text, or PICTs }
- { as well as the Grow Icon and Window Menu Bar if any. }
- { ==================================================== }
-
- PROCEDURE HandleUpdate;
-
- VAR
- savedPort: GrafPtr; { Must be local parms because windows }
- savedWindType: INTEGER; { are updated in front-to-back order: }
- savedHasGrowIcon: BOOLEAN;
- savedMBar: wMenuBarHandle;
- savedWBMrect, savedLeftMSArect, savedRightMSArect: Rect;
- window: WindowPtr;
-
-
- BEGIN
-
- GetPort(savedPort); { Save stuff ... }
- savedWindType := windType;
- savedHasGrowIcon := hasGrowIcon;
- savedMBar := mBar;
- savedWBMrect := WBMrect;
- savedLeftMSArect := leftMSArect;
- savedRightMSArect := rightMSArect;
-
- window := WindowPtr(Event.message);
- SetPort(window);
- windType := GetWindowType(window); { Quantifies "hasGrowIcon". }
-
- BeginUpDate(window);
- ;
- DrawContents(window);
- ;
- EndUpdate(window);
-
- SetPort(savedPort); { Reset stuff ... }
- windType := savedWindType;
- hasGrowIcon := savedHasGrowIcon;
- mBar := savedMBar;
- WBMrect := savedWBMrect;
- leftMSArect := savedLeftMSArect;
- rightMSArect := savedRightMSArect;
-
- IF NOT EventAvail(updateMask, Event) THEN
- brandNew := FALSE; { Everything's updated, already !! }
-
- END; { HandleUpdate }
-
-
-
- { ----------------------------------------------- }
- { Need to separate them because we're trying to }
- { make this blasted thing MultiFinder-compatible: }
- { ----------------------------------------------- }
-
- PROCEDURE DoDeactivate (window: WindowPtr);
-
- BEGIN
-
- { Remember, deActivate & Activate Events generally come in pairs, }
- { with deActivate first in line. SO ... we hide the silly things }
- { and re-show them after the Resume partner has finished. }
- IF NOT InForeGround THEN { A suspend Event. }
- BEGIN
- saveBalloons := balloonsUp; { Where we're at !!! }
- ResetBalloons(startBalloons); { On Day Numero Uno !!! }
- END;
-
- IF window = NIL THEN { Window or not, we still do the Balloon-thing !! }
- EXIT(DoDeactivate);
-
- GetWBMrects(window, WBMrect, leftMSArect, rightMSArect);
- IF NOT EmptyRect(WBMrect) THEN
- BEGIN
-
- gWBMrect := WBMrect;
- LocalGlobal(gWBMrect);
- IF SectRect(gWBMrect, gScreen, visRect) THEN
- BEGIN
- GlobalLocal(visRect);
- onScreenRgn := NewRgn;
- RectRgn(onScreenRgn, visRect);
- SectRgn(onScreenRgn, window^.visRgn, onScreenRgn);
- DimRgn(onScreenRgn);
- DisposeRgn(onScreenRgn);
- END; { IF part of WBMrect is visible }
-
- END; { IF window has a Menu Bar }
-
- IF textH <> NIL THEN
- TEDeActivate(textH);
- ourControl := ScrollHoriz(window);
- IF ourControl <> NIL THEN
- HiliteControl(ourControl, 255);
- ;
- ourControl := ScrollVert(window);
- IF ourControl <> NIL THEN
- HiliteControl(ourControl, 255);
- ;
- IF hasGrowIcon THEN
- DrawGrowIcon(window);
-
- myAppl := FALSE;
-
- END; { DoDeactivate }
-
-
-
- PROCEDURE DoActivate (window: WindowPtr);
-
- BEGIN
-
- IF NOT InForeGround THEN { Previously suspended. }
- BEGIN
- ResetBalloons(saveBalloons);
- balloonsUp := saveBalloons;
- END;
-
- IF window = NIL THEN { ????? }
- EXIT(DoActivate);
-
- mBar := wGetMenuBar(window);
- IF (mBar <> NIL) & NOT brandNew THEN
- BEGIN
- wDrawMSA(mBar);
- wDrawMenuBar(mBar);
- END; { window has a WBM }
-
- textH := TEHandle(GetWRefCon(window));
- IF textH <> NIL THEN
- TEActivate(textH);
-
- IF NOT brandNew THEN { Let update Event handle it. }
- BEGIN
- ourControl := ScrollHoriz(window);
- IF ourControl <> NIL THEN
- HiliteControl(ourControl, 0);
- ;
- ourControl := ScrollVert(window);
- IF ourControl <> NIL THEN
- HiliteControl(ourControl, 0);
- ;
- IF hasGrowIcon THEN
- DrawGrowIcon(window);
- END; { NOT brandNew }
-
- myAppl := TRUE;
-
- END; { DoActivate }
-
-
-
- PROCEDURE HandleActivate;
-
- VAR
- window: WindowPtr;
-
-
- BEGIN
-
- window := WindowPtr(Event.message);
- SetPort(window);
- windType := GetWindowType(window);
-
- IF ODD(Event.modifiers) THEN
- DoActivate(window)
- ELSE
- DoDeactivate(window);
-
- PeriodicMenus; { Crisper appearance if here also. }
-
- END; { HandleActivate }
-
-
-
- PROCEDURE System7Braggart;
-
- CONST
- kSystem7 = 132;
-
- VAR
- theWorld: SysEnvRec;
- itDoesMatter: OSErr;
- oldPort: GrafPtr;
- window: WindowPtr;
- myPic: PicHandle;
- wpRect, picRect: Rect;
-
-
- BEGIN
-
- itDoesMatter := SysEnvirons(SysEnvironsVersion, theWorld);
- IF (itDoesMatter = noErr) & (theWorld.systemVersion >= $0700) THEN
- BEGIN
-
- GetPort(oldPort);
-
- window := GetNewWindow(kSystem7, NIL, WindowPtr(-1));
- IF window <> NIL THEN
- BEGIN
- SetPort(window);
- wpRect := window^.portRect;
- ClipRect(wpRect);
- myPic := GetPicture(kSystem7);
- ;
- IF myPic <> NIL THEN
- BEGIN
- picRect := wpRect;
- InsetRect(picRect, 1, 1);
- DrawPicture(myPic, picRect); { ... so it's centered. }
- Delay(60, finalTicks);
- InvertRect(wpRect);
- Delay(120, finalTicks);
- KillPicture(myPic);
- END; { Got a picture }
- ;
- DisposeWindow(window);
- END; { Got a window }
-
- SetPort(oldPort);
-
- END; { Got System 7 }
-
- END; { System7Braggart }
-
-
-
- PROCEDURE DoSpiffyIris;
-
- LABEL
- 100, 200, 300;
-
- CONST
- bragWindowID = 999;
- logoPicID = 131; { picFrame := 54,126,251,540 }
-
- VAR
- bragging: WindowPtr;
- logoPicHdl: PicHandle;
- tempX, tempY: INTEGER;
- windRect, pictRect, bragRect, irisRect: Rect;
- irisRgn: RgnHandle;
- maskPercent: INTEGER;
- bragOSHdl: OffScreenRecHdl;
-
-
- BEGIN
-
- SetCursor(GetCursor(watchCursor)^^);
- GetPort(oldPort);
-
- { Calling GetNewCWindow if "aMac2" spoils the automatic centering }
- { provided by the added "centerMainScreen" field in the rez file. }
- bragging := GetNewWindow(bragWindowID, NIL, WindowPtr(-1));
- IF bragging = NIL THEN
- GOTO 300;
- SetPort(bragging);
- CalcVis(WindowPeek(bragging)); { TOM INIT. }
- ;
- logoPicHdl := GetPicture(logoPicID);
- IF logoPicHdl = NIL THEN
- GOTO 200;
- HLock(Handle(logoPicHdl));
-
- { Need an instantaneous deActivate Event }
- { for any window formerly in front. }
- IF WNE THEN
- WHILE WaitNextEvent(activMask, Event, Sleep, NIL) DO
- HandleActivate
- ELSE
- WHILE GetNextEvent(activMask, Event) DO
- HandleActivate;
-
- bragRect := bragging^.portRect;
-
- WITH bragRect DO
- BEGIN
- { IF ScrollVert(bragging) <> NIL THEN }
- { right := (right + frame) - scrollWidth; }
- { IF ScrollHoriz(bragging) <> NIL THEN }
- { bottom := (bottom + frame) - scrollHeight; }
- tempX := right - left;
- tempY := bottom - top;
- END; { WITH bragRect }
-
- { Because I know my WINDow & PICT sizes, tempX & tempY are always > 0: }
- WITH logoPicHdl^^.picFrame DO
- BEGIN
- tempX := tempX - (right - left);
- tempY := tempY - (bottom - top);
- END; { WITH logoPicHdl^^.picFrame }
-
- WITH bragRect DO
- BEGIN
- tempX := left + tempX DIV 2;
- tempY := top + tempY DIV 2;
- END; { WITH bragRect }
-
- { ------------------------------------------- }
- { Place my PICTure into an off screen BitMap. }
- { ------------------------------------------- }
-
- bragOSHdl := CreateOffScreen(bragRect); { Local window in, local screen back. }
- IF bragOSHdl^^.CreateOffScreenError <> noErr THEN
- GOTO 100;
-
- ClipRect(bragRect); { Draw off-screen ... }
- EraseRect(bragRect); { Eliminate all stray matter. }
- pictRect := bragRect; { Center the PICT ... }
- InsetRect(pictRect, tempX, tempY);
- DrawPicture(logoPicHdl, pictRect);
-
- ToOnScreen(bragOSHdl); { Back to "Square 1". }
- windRect := bragOSHdl^^.drawingRect;
- ClipRect(windRect);
- InvertRect(windRect);
-
- BackColor(whiteColor);
- ForeColor(blackColor);
- { ---------- }
- maskPercent := 99; { Initialize some stuff ... }
- WITH windRect DO
- BEGIN
- tempX := (right - left) DIV 2;
- tempY := (bottom - top) DIV 2;
- END; { WITH drawingRect }
- ;
- WHILE maskPercent >= 0 DO
- BEGIN
- irisRect := windRect;
- InsetRect(irisRect, (tempX * maskPercent) DIV 100, (tempY * maskPercent) DIV 100);
- irisRgn := NewRgn;
- OpenRgn;
- WITH irisRect DO
- FrameRoundRect(irisRect, ((right - left) * maskPercent) DIV 100, ((bottom - top) * maskPercent) DIV 100);
- CloseRgn(irisRgn);
- WITH bragOSHdl^^ DO
- BEGIN
- SectRgn(irisRgn, origPort^.visRgn, irisRgn);
- CopyBits(offBitMapPtr^, origPort^.portBits, bragRect, drawingRect, srcCopy, irisRgn);
- END;
- DisposeRgn(irisRgn);
- ;
- IF aMac2 THEN
- IF colorDepth = 1 THEN
- Delay(4, finalTicks) { Black-and-white too doggone fast !! }
- ELSE
- Delay(2, finalTicks) { Color a tad better. }
- ELSE
- Delay(1, finalTicks);
- ;
- maskPercent := maskPercent - 1;
- END; { WHILE maskPercent >= 0 }
- { ---------- }
- Delay(120, finalTicks); { Take a gander at its beauty !! }
-
- 100:
- DisposOffScreen(bragOSHdl);
-
- HUnlock(Handle(logoPicHdl));
- ReleaseResource(Handle(logoPicHdl));
- 200:
- DisposeWindow(bragging); { Activates the window behind it. }
- 300:
- SysBeep(10); { Wake Up Call !! }
-
- SetPort(oldPort);
- InitCursor; { Just in case a DA doesn't ... }
- HandleCursor; { So CURSor changes immediately. }
-
- END; { DoSpiffyIris }
-
-
-
- { ---------------------------------------------- }
- { DoApple is the code for the main "Apple" Menu. }
- { The other two main Menus follow. }
- { ---------------------------------------------- }
-
- PROCEDURE DoApple (item: INTEGER);
-
- VAR
- accName: Str255;
- accNumber: INTEGER;
-
-
- BEGIN
-
- CASE item OF
-
- AboutItem:
- DoSpiffyIris;
-
- AdisabledItem: { NEVER seen -- shown for completeness, only. }
- BEGIN
- END; { AdisabledItem }
-
- OTHERWISE
- BEGIN
- GetPort(oldPort);
- ;
- GetItem(AppleMenu, item, accName);
- accNumber := OpenDeskAcc(accName);
- ;
- SetPort(oldPort);
- END; { OTHERWISE }
-
- END; { CASE...OF }
-
- END; { DoApple }
-
-
-
- PROCEDURE DoFile (item: INTEGER);
-
-
- BEGIN
-
- CASE item OF
-
- NewWindowItem:
- ignore := DoNewWindow(newWindowID, wMBARID, offset);
-
- CloseWindowItem:
- CloseOurWindow(FrontWindow);
-
- FdisabledItem:
- BEGIN
- END;
-
- QuitItem:
- BEGIN
- Delay(flashDelay, finalTicks); { Don't ask ????? }
- DoQuit;
- END;
-
- OTHERWISE
- BEGIN
- END; { OTHERWISE }
-
- END; { CASE...OF }
-
- END; { DoFile }
-
-
-
- PROCEDURE DoEdit (item: INTEGER);
-
- BEGIN
-
- IF SystemEdit(item - 1) THEN
- EXIT(DoEdit); { DAs do their own thing !! }
-
- CASE item OF
-
- UndoItem, EdisabledItem, CutItem, CopyItem, PasteItem, ClearItem:
- BEGIN
- END;
-
- END; { CASE...OF }
-
- END; { DoEdit }
-
-
-
- PROCEDURE DoWindow (item: INTEGER);
-
- VAR
- wPeek: WindowPeek;
- itemString, wpTitle: Str255;
-
-
- BEGIN
-
- IF (gInitAppleEvents = noErr) & (item = AEWindItem) THEN
- CreateAndSendAE(kMoveWindClass, kMoveWindID)
- ELSE IF item = firstWindowItem - 2 THEN
- BEGIN
-
- wPeek := WindowPeek(FrontWindow)^.nextWindow;
- { System 6.xx w/DA in application heap: }
- WHILE (wPeek <> NIL) & (wPeek^.windowKind <> userKind) DO
- wPeek := wPeek^.nextWindow;
- ;
- IF wPeek <> NIL THEN
- BEGIN
- SelectWindow(WindowPtr(wPeek));
- UncheckOldItem(WindowMenu); { Un-check old item ... }
- item := ItemFromName(wPeek^.titleHandle^^);
- CheckItem(WindowMenu, item, true); { & check the new one. }
- END; { wPeek <> NIL }
-
- END { ELSE IF "Next window" }
- ELSE
- BEGIN
-
- GetItem(WindowMenu, item, itemString);
- wPeek := WindowPeek(FrontWindow);
- ;
- WHILE wPeek <> NIL DO
- BEGIN
- IF wPeek^.windowKind = userKind THEN
- BEGIN
- wpTitle := wPeek^.titleHandle^^;
- IF itemString = wpTitle THEN
- Leave; { WHILE loop }
- END;
- wPeek := wPeek^.nextWindow;
- END; { WHILE }
-
- IF wPeek <> NIL THEN
- BEGIN
- SelectWindow(WindowPtr(wPeek));
- UncheckOldItem(WindowMenu);
- CheckItem(WindowMenu, item, true);
- END;
-
- END; { ELSE }
-
- END; { DoWindow }
-
-
-
- { ----------------------------------------------------- }
- { DoWBMApple is the code for the window's "Apple" Menu. }
- { The other two window Menus follow. }
- { ----------------------------------------------------- }
-
- PROCEDURE DoWBMApple (item: INTEGER);
-
- VAR
- accName: Str255;
- accNumber: INTEGER;
-
-
- BEGIN
-
- CASE item OF
-
- wAboutItem:
- DoSpiffyIris;
-
- wAdisabledItem: { NEVER seen -- shown for completeness, only. }
- BEGIN
- END; { wAdisabledItem }
-
- OTHERWISE
- BEGIN
- GetPort(oldPort);
- ;
- GetItem(AppleMenu, item, accName);
- accNumber := OpenDeskAcc(accName);
- ;
- SetPort(oldPort);
- END; { OTHERWISE }
-
- END; { CASE...OF }
-
- END; { DoWBMApple }
-
-
-
- PROCEDURE DoWBMFile (item: INTEGER);
-
-
- BEGIN
-
- CASE item OF
-
- wNewWindowItem:
- ;
-
- wCloseWindowItem:
- ;
-
- wFdisabledItem:
- BEGIN
- END;
-
- wQuitItem:
- DoQuit;
-
- OTHERWISE
- BEGIN
- END; { OTHERWISE }
-
- END; { CASE...OF }
-
- END; { DoWBMFile }
-
-
-
- PROCEDURE DoWBMNewHier (item: INTEGER);
-
-
- BEGIN
-
- CASE item OF
-
- wNewHierItem:
- ;
-
- OTHERWISE
- ;
-
- END; { CASE }
-
- END; { DoWBMNewHier }
-
-
-
- PROCEDURE DoWBMCloseHier (item: INTEGER);
-
-
- BEGIN
-
- CASE item OF
-
- wCloseHierItem:
- ;
-
- OTHERWISE
- ;
-
- END; { CASE }
-
- END; { DoWBMCloseHier }
-
-
-
- PROCEDURE DoWBMHierHier (item: INTEGER);
-
-
- BEGIN
-
- CASE item OF
-
- wHierHierItem:
- PlaySound('Bush Inauguration Speech');
-
- OTHERWISE
- ;
-
- END; { CASE }
-
- END; { DoWBMHierHier }
-
-
-
- PROCEDURE DoWBMEdit (item: INTEGER);
-
- BEGIN
-
- IF SystemEdit(item - 1) THEN
- EXIT(DoWBMEdit); { DAs do their own thing !! }
-
- CASE item OF
-
- wUndoItem, wEdisabledItem, wCutItem, wCopyItem, wPasteItem, wClearItem:
- BEGIN
- END;
-
- END; { CASE...OF }
-
- END; { DoWBMEdit }
-
-
-
- { ------------------------------------------------------------ }
- { HandleMainMenu is the dispatch routine for the main MenuBar. }
- { The item selected is passed to the appropriate menu handler. }
- { ------------------------------------------------------------ }
-
- PROCEDURE HandleMainMenu;
-
- VAR
- menuCode: LONGINT;
- charCode: INTEGER;
-
- BEGIN
- IF Event.what = MouseDown THEN
- menuCode := MenuSelect(Event.where)
- ELSE
- BEGIN
- charCode := BitAnd(Event.message, CharCodeMask);
- menuCode := MenuKey(CHR(charCode));
- END; { ELSE }
-
- CASE HiWord(menuCode) OF
- AppleMenuID:
- DoApple(LoWord(menuCode));
-
- FileMenuID:
- DoFile(LoWord(menuCode));
-
- EditMenuID:
- DoEdit(LoWord(menuCode));
-
- mWindow:
- DoWindow(LoWord(menuCode));
-
- kHMHelpMenuID:
- IF LoWord(menuCode) = origNumHelpItems + 1 THEN
- { User selected my Item which I appended in "SetupMainMenus" PROC. }
- DoSpiffyIris;
-
- OTHERWISE
- IF Event.what = KeyDown THEN
- SysBeep(10);
- END; { CASE }
-
- HiliteMenu(0)
- END; { HandleMainMenu }
-
-
-
- { ----------------------------------------------------------- }
- { Ditto for the Window Bar Menu, except for a slight twist. }
- { The change from a PROCEDURE to a FUNCTION is required when }
- { a CMD-key is pressed. The Window Menus take precedence and }
- { if the CMD-key is not found in the window's Menu List, then }
- { we go to "HandleMainMenu". }
- { ----------------------------------------------------------- }
-
- FUNCTION HandleWBMenu (theMenuBar: wMenuBarHandle): BOOLEAN;
-
- VAR
- WBMenuCode: LONGINT;
- WBMCharCode: INTEGER;
-
- BEGIN
-
- HandleWBMenu := TRUE; { Be optimistic !! }
-
- IF Event.what = MouseDown THEN
- WBMenuCode := wMenuSelect(theMenuBar, Event.where)
- ELSE
- BEGIN
- WBMCharCode := BitAnd(Event.message, CharCodeMask);
- WBMenuCode := wMenuKey(theMenuBar, CHR(WBMCharCode));
- END; { ELSE }
-
- CASE HiWord(WBMenuCode) OF
- wAppleMenuID:
- DoWBMApple(LoWord(WBMenuCode));
- wFileMenuID:
- DoWBMFile(LoWord(WBMenuCode));
- wEditMenuID:
- DoWBMEdit(LoWord(WBMenuCode));
- wNewHierMenuID: { Sub-menus under "File" ... }
- DoWBMNewHier(LoWord(WBMenuCode));
- wCloseHierMenuID:
- DoWBMCloseHier(LoWord(WBMenuCode));
- wHierHierMenuID:
- DoWBMHierHier(LoWord(WBMenuCode));
- OTHERWISE
- IF Event.what = KeyDown THEN
- HandleWBMenu := FALSE;
- END; { CASE }
-
- wHiliteMenu(theMenuBar, 0)
-
- END; { HandleWBMenu }
-
-
-
- PROCEDURE SetUpMainMenus;
-
- CONST
- none = 0;
-
- VAR
- theWorld: SysEnvRec;
- takeItOrLeaveIt: OSErr;
-
-
- BEGIN
-
- AppleMenu := GetMenu(AppleMenuID);
- takeItOrLeaveIt := SysEnvirons(1, theWorld);
- IF theWorld.systemVersion < $0700 THEN
- BEGIN
- SetItemIcon(AppleMenu, AboutItem, none);
- SetItemCmd(AppleMenu, AboutItem, char(none));
- END;
- InsertMenu(AppleMenu, 0);
- AddResMenu(AppleMenu, 'DRVR'); { + DAs }
- ;
- FileMenu := GetMenu(FileMenuID);
- InsertMenu(FileMenu, 0);
- { myAppl := TRUE; -- taken care of by 1st Activate Event. }
- prevWind := TRUE;
- ;
- EditMenu := GetMenu(EditMenuID);
- InsertMenu(EditMenu, 0);
- prevDA := FALSE;
- ;
- AddWindowMenu;
-
- HelpMenu := NIL;
- IF HelpManagerActive THEN
- IF HMGetHelpMenuHandle(HelpMenu) = noErr THEN
- IF HelpMenu <> NIL THEN
- BEGIN
- origNumHelpItems := CountMItems(HelpMenu);
- AppendMenu(HelpMenu, 'About Window Bar Menu Demo ...');
- END;
-
- DrawMenuBar;
-
- END; { SetUpMainMenus }
-
-
-
- { --------------------------------------------------------------- }
- { Make a separate PROC so we can zoom independently of _TrackBox, }
- { for example, in response to a Menu selection or a keypress: }
- { --------------------------------------------------------------- }
-
- PROCEDURE doZoom (window: WindowPtr; zoomDir: INTEGER);
- { Reference: Tech Note #79 }
-
- TYPE
- WStateDataPtr = ^WStateData;
- WStateDataHandle = ^WStateDataPtr;
-
- VAR
- windRect, zoomRect: Rect;
- dominantGDevice: GDHandle;
- bias: INTEGER;
-
-
- BEGIN
-
- IF NOT applWind THEN
- EXIT(doZoom);
- ;
- GetPort(oldPort);
- SetPort(window);
-
- { If there is the possibility of multiple gDevices, then we must check them }
- { to make sure we are zooming onto the right display device when zooming out. }
- IF (zoomDir = inZoomOut) AND aMac2 THEN
- BEGIN
-
- { Window's portRect must be converted to global coordinates: }
- windRect := window^.portRect;
- LocalGlobal(windRect);
-
- { Must calculate height of window's title bar }
- bias := windRect.top - 1 - WindowPeek(window)^.strucRgn^^.rgnBBox.top;
- windRect.top := windRect.top - bias;
-
- dominantGDevice := GetMaxAreaDevice(windRect);
-
- { We must create a zoom rectangle manually in this case & }
- { account for menu bar height as well, if on main device. }
- IF dominantGDevice = GetMainDevice THEN
- bias := bias + mBarHt;
- WITH dominantGDevice^^.gdRect DO
- SetRect(zoomRect, left + 3, top + bias + 3, right - 3, bottom - 3);
-
- { Set up the WStateData record for this window. }
- WStateDataHandle(WindowPeek(window)^.dataHandle)^^.stdState := zoomRect;
-
- END; { inZoomOut & color Quickdraw }
-
- EraseRect(window^.portRect);
- ShowHide(window, FALSE);
- ZoomWindow(window, zoomDir, FALSE); { NO Activate Event !! }
- InvalRect(window^.portRect);
- ScrollResize(window);
- wChangeMenuBarSize(window, zooming);
- ShowHide(window, TRUE);
-
- CASE zoomDir OF
-
- inZoomOut:
- PlaySound('ZoomOut');
-
- inZoomIn:
- PlaySound('ZoomIn');
-
- OTHERWISE { Nada !! }
- BEGIN
- END;
-
- END; { CASE }
-
- SetPort(oldPort);
-
- END; { doZoom }
-
-
-
- PROCEDURE HandleMouse;
-
- CONST
- growing = NOT zooming;
-
- VAR
- dragRect, windRect, growRect: Rect;
- newSize: LONGINT;
- titleBarHeight, windWidth, windHt, tempINT, i: INTEGER;
- mouseLoc: Point;
- partControl: INTEGER;
- dontCareThisTimeAboutTheResult: BOOLEAN;
-
-
- BEGIN
-
- CASE windowLoc OF
-
- inDesk:
- BEGIN
-
- END; { inDesk }
-
- inMenuBar:
- HandleMainMenu;
-
- inSysWindow:
- SystemClick(Event, TheWindow); { TheWindow = DA window }
-
- inContent:
- BEGIN
-
- IF TheWindow <> FrontWindow THEN
- BEGIN
- SelectWindow(TheWindow); { Generates an Activate Event. }
- IF WindowPeek(TheWindow)^.windowKind = userKind THEN
- BEGIN
- UncheckOldItem(WindowMenu);
- GetWTitle(TheWindow, windowName);
- CheckItem(WindowMenu, ItemFromName(windowName), true);
- END; { userKind }
- EXIT(HandleMouse);
- END; { IF TheWindow <> FrontWindow }
-
- mouseLoc := Event.where;
- GlobalToLocal(mouseLoc);
- partControl := FindControl(mouseLoc, TheWindow, ourControl);
- IF partControl <> 0 THEN { Nada !! }
- BEGIN
-
- END
-
- { mBar & rects gotten from "DoActivate" or "HandleUpdate" }
- ELSE IF (mBar <> NIL) & PtInRect(mouseLoc, WBMrect) THEN
- BEGIN
-
- HideBalloons(balloonsUp); { ... IF they're showing to begin with. }
- ;
- IF PtInRect(mouseLoc, leftMSArect) | PtInRect(mouseLoc, rightMSArect) THEN
- wScrollMenuBar(mBar)
- ELSE
- dontCareThisTimeAboutTheResult := HandleWBMenu(mBar);
- ;
- ShowBalloons(balloonsUp); { ... that is if they were up initially. }
-
- END { somewhere in the WBM }
-
- ELSE IF DoubleClick THEN { NO mBar or NOT in WBMrect }
- DoFile(QuitItem);
-
- END; { inContent }
-
- inDrag:
- BEGIN
-
- IF balloonsUp THEN
- BEGIN
- HideBalloons(true);
- IF EventAvail(updateMask, Event) THEN
- { Need an instantaneous update Event because of the Title Bar's balloon: }
- IF WNE THEN
- WHILE WaitNextEvent(updateMask, Event, Sleep, NIL) DO
- HandleUpdate
- ELSE
- WHILE GetNextEvent(updateMask, Event) DO
- HandleUpdate;
- END; { IF }
-
- dragRect := gScreen; { Includes main MenuBar. }
- ;
- WITH dragRect DO
- BEGIN
- top := top + mBarHt; { Back to exclude. }
- { Do NOT hide part of wMenuBar when dragging to bottom: }
- IF mBar <> NIL THEN
- bottom := bottom - mBarHt;
- InsetRect(dragRect, 10, 0); { + horizontal = just a tad. }
- { Do NOT hide part of window's title bar. }
- { May be CMD-dragging, so we have to save & restore thePort: }
- GetPort(oldPort);
- SetPort(TheWindow);
- windRect := TheWindow^.portRect;
- LocalGlobal(windRect);
- titleBarHeight := windRect.top - 1 - WindowPeek(TheWindow)^.strucRgn^^.rgnBBox.top;
- InsetRect(dragRect, 0, titleBarHeight);
- SetPort(oldPort);
- END; { WITH dragRect }
-
- { _DragWindow forces the Mouse to stay inside of dragRect. }
- DragWindow(TheWindow, Event.where, dragRect);
-
- ShowBalloons(balloonsUp);
-
- IF EventAvail(activMask, Event) THEN
- IF WindowPeek(TheWindow)^.windowKind = userKind THEN
- BEGIN
- UncheckOldItem(WindowMenu);
- GetWTitle(TheWindow, windowName);
- CheckItem(WindowMenu, ItemFromName(windowName), true);
- END; { pending activate Event + userKind }
-
- END; { inDrag }
-
- inGrow:
- BEGIN
-
- WITH lScreen DO
- SetRect(growRect, 2 * title, 2 * title, right - left, bottom - top);
-
- WITH growRect DO
- BEGIN
- IF hasGrowIcon THEN
- BEGIN
- top := top + growBoxSize;
- left := left + growBoxSize;
- END;
-
- IF ScrollVert(TheWindow) <> NIL THEN
- BEGIN
- tempINT := (7 * scrollHeight) DIV 2 + growBoxSize;
- IF tempINT > top THEN
- top := tempINT;
- END;
- ;
- IF ScrollHoriz(TheWindow) <> NIL THEN
- BEGIN
- tempINT := (7 * scrollWidth) DIV 2 + growBoxSize;
- IF tempINT > left THEN
- left := tempINT;
- END;
-
- IF mBar <> NIL THEN
- BEGIN
- tempINT := leftMSArect.right - leftMSArect.left + StringWidth('ABCDE') + rightMSArect.right - rightMSArect.left;
- IF tempINT > left THEN
- left := tempINT;
- tempINT := 2 * mBarHt;
- IF tempINT > top THEN
- top := tempINT;
- END;
- END; { WITH growRect }
-
- newSize := GrowWindow(TheWindow, Event.where, growRect);
- IF newSize = 0 THEN
- EXIT(HandleMouse); { NO change. }
-
- { ALL of the following just to avoid that pesky (ARRGH !!!) }
- { double re-draw of the Scroll Bars. [See _ValidRect within }
- { "Inside Macintosh"] In addition, note that we start out }
- { by erasing the grow box because upon enlarging the window, }
- { the grow icon remains drawn where it used to be just for a }
- { split second until _BeginUpdate ... _EndUpdate gets around }
- { to erasing it. }
-
- IF hasGrowIcon THEN
- WITH updateRect DO
- BEGIN
- updateRect := TheWindow^.portRect;
- left := right + frame - growBoxSize;
- top := bottom + frame - growBoxSize;
- EraseRect(updateRect);
- END; { Erasing grow box }
- InvalidScroll(TheWindow);
- wChangeMenuBarSize(TheWindow, growing);
- SizeWindow(TheWindow, LoWord(newSize), HiWord(newSize), TRUE);
- wChangeMenuBarSize(TheWindow, growing);
- ScrollResize(TheWindow);
- ValidScroll(TheWindow);
- IF hasGrowIcon THEN
- DrawGrowIcon(TheWindow);
-
- END; { inGrow }
-
- inGoAway:
- BEGIN
-
- IF TrackGoAway(TheWindow, Event.where) THEN
- CloseOurWindow(TheWindow);
-
- END; { inGoAway }
-
- inZoomOut, inZoomIn:
- IF TrackBox(TheWindow, Event.where, windowLoc) THEN
- BEGIN
- doZoom(TheWindow, windowLoc);
- WITH mBar^^ DO
- IF windowLoc = inZoomOut THEN
- BEGIN
-
- { Scroll right now = back to scratch: }
- tempInt := leftMSArect.right + betweenTitles - invertOverlap - wMenus[0].titleRect.left;
- { Scroll left upon returning = where we are now: }
- saveCumScrollMenuX := -tempInt;
- { Gotta PRE-scroll, otherwise Window Menu Bar is cut off }
- { at left since we do NOT keep the off-screen Map around. }
- FOR i := 0 TO (numMenus - 1) DO
- OffsetRect(wMenus[i].titleRect, tempInt, 0);
-
- END
- ELSE { zooming back in }
- FOR i := 0 TO (numMenus - 1) DO
- OffsetRect(wMenus[i].titleRect, saveCumScrollMenuX, 0);
- END; { zooming }
-
- END; { CASE }
-
- END; { HandleMouse }
-
-
-
- PROCEDURE HandleKey;
-
- VAR
- keyASCII: INTEGER;
- yourBalloonIsShowing, handledByWBM: BOOLEAN;
-
-
- BEGIN
-
- IF NOT myAppl THEN
- EXIT(HandleKey);
-
- IF BitAnd(Event.modifiers, $0F00) = cmdKey THEN { ONLY the Command Key }
- IF applWind THEN
- BEGIN
- mBar := wGetMenuBar(FW);
- ;
- IF mBar <> NIL THEN
- BEGIN
- yourBalloonIsShowing := BalloonShowing;
- HideBalloons(yourBalloonIsShowing);
- handledByWBM := HandleWBMenu(mBar);
- ShowBalloons(yourBalloonIsShowing);
- END { a WBMenu }
- ELSE
- handledByWBM := FALSE;
- ;
- IF NOT handledByWBM THEN
- HandleMainMenu;
- END
- ELSE { NO windows at all !! }
- HandleMainMenu
-
- ELSE { no Command Key }
-
- BEGIN
- keyASCII := BitAnd(Event.message, CharCodeMask);
- IF keyASCII = Enter THEN
- DoQuit;
- END; { ELSE no Command Key }
-
- END; { HandleKey }
-
-
-
- PROCEDURE DoPeriodic;
-
-
- BEGIN
-
- IF NOT WNE THEN
- SystemTask;
-
- aMac2 := TestForColor(colorDepth);
- PeriodicMenus; { Feeds HandleCursor ... }
- HandleCursor;
- IF InForeGround THEN
- BEGIN
- IF applWind THEN
- IF textH <> NIL THEN
- TEIdle(textH);
- balloonsUp := BalloonsOn;
- FindAndShowDynamicBalloons(balloonsUp, FW);
- END
- ELSE
- startBalloons := BalloonsOn;
- ;
- IF Sleep = 1 THEN
- Sleep := GetCaretTime; { Reset after special effects. }
-
- { Problems with "Switch-A-Roo" ... }
- { It eliminates my Help MENU item. }
- IF myAppl THEN
- { For some ??? reason the next two IFs are required here }
- { even though "SetupMainMenus" would not have a non-NIL }
- { Help MenuHandle unless they were true. }
- IF HelpManagerActive THEN
- IF HMGetHelpMenuHandle(HelpMenu) = noErr THEN
- IF HelpMenu <> NIL THEN
- IF CountMItems(HelpMenu) = origNumHelpItems THEN
- AppendMenu(HelpMenu, 'About Window Bar Menu Demo ...');
-
- END; { DoPeriodic }
-
-
-
- PROCEDURE MainEventLoop;
-
- BEGIN
-
- REPEAT
-
- IF WNE THEN
- ignore := WaitNextEvent(everyEvent, Event, Sleep, NIL)
- ELSE
- ignore := GetNextEvent(everyEvent, Event);
-
- CASE Event.what OF
-
- NullEvent:
- DoPeriodic;
-
- MouseDown:
- BEGIN
- windowLoc := FindWindow(Event.where, TheWindow); { Fills in 'TheWindow'. }
- HandleMouse;
- END;
-
- MouseUp:
- BEGIN
- END;
-
- KeyDown, AutoKey:
- HandleKey;
-
- KeyUp:
- BEGIN
- END;
-
- UpdateEvt:
- HandleUpdate;
-
- DiskEvt:
- BEGIN
- END;
-
- ActivateEvt:
- HandleActivate;
-
- NetworkEvt, DriverEvt:
- BEGIN
- END;
-
- App1Evt, App2Evt, App3Evt:
- BEGIN
- END;
-
- OSEvt: { MultiFinder Event = app4Evt }
-
- BEGIN
-
- CASE BSR(Event.message, 24) OF { High byte }
-
- mouseMovedMessage:
- HandleCursor;
-
- suspendResumeMessage:
-
- BEGIN
-
- IF BAND(Event.message, resumeFlag) <> 0 THEN
- BEGIN
- DoActivate(FrontWindow);
- InForeGround := TRUE;
- END { Resume }
- ELSE { Suspend }
- BEGIN
- InForeGround := FALSE;
- DoDeactivate(FrontWindow);
- END; { ELSE }
-
- END; { suspendResumeMessage }
-
- OTHERWISE
- END; { CASE BSR(Event.message, 24) OF }
-
- END; { MultiFinder Event }
-
- kHighLevelEvent:
- BEGIN
-
- HideBalloons(balloonsUp); { ... because of my Alert Dialog. }
- IF HelpManagerActive THEN
- IF HMGetHelpMenuHandle(HelpMenu) = noErr THEN
- IF HelpMenu <> NIL THEN
- BEGIN
- DisableItem(HelpMenu, kHMShowBalloonsItem); { Keep them hidden. }
- DrawMenuBar;
- END;
- ;
- DoHighLevelEvent(Event);
- ;
- ShowBalloons(balloonsUp);
- IF HelpManagerActive THEN
- IF HMGetHelpMenuHandle(HelpMenu) = noErr THEN
- IF HelpMenu <> NIL THEN
- BEGIN
- EnableItem(HelpMenu, kHMShowBalloonsItem); { Reset them. }
- DrawMenuBar;
- END;
-
- END; { HighLevelEvent }
-
- OTHERWISE
- END; { CASE Event.what OF }
-
- UNTIL Done;
-
- END; { MainEventLoop }
-
-
-
-
- BEGIN { Program }
-
- InitManagers; { The usual stuff ... }
- ;
- ROM := wordPtr(ROM85Loc); { Quantify some globals ... }
- IF ROM^ > 0 THEN
- mBarHt := GetMBarHeight
- ELSE
- ExitToShell; { NO workee !!! }
- ;
- gInitAppleEvents := InitAppleEvents; { errs in "myAppleEvents.p" ... }
- gInitPPCToolbox := InitPPCToolbox;
-
- SetCursor(GetCursor(watchCursor)^^);
- ;
- lScreen := screenBits.bounds;
- gScreen := GetGrayRgn^^.rgnBBox;
- WITH gScreen DO
- top := top - mBarHt; { Include main MenuBar. }
- WITH lScreen DO
- OffsetRect(gScreen, -left, -top); { _LocalToGlobal }
- ;
- gStripAddressMask := GetStripAddressMask;
-
- aMac2 := TestForColor(colorDepth); { Feeds InitBigScreen. }
- InitBigScreen(FPDRsrc, sizeFont); { Feeds wInitMenus. }
- mBarList := wInitMenus; { ... not so usual. }
- IF mBarList = NIL THEN
- ExitToShell;
- ;
- windowStorage := InitWindowStorage;
- IF windowStorage = NIL THEN
- BEGIN
- DisposHandle(Handle(mBarList));
- ExitToShell;
- END;
-
- Done := FALSE; { Init some other globals ... }
- InForeGround := TRUE; { Assume UniFinder. }
- WNE := WNEisImplemented;
- Sleep := GetCaretTime;
- SetPt(offset, 0, 0); { NO offset for the first window. }
- SetPt(deltaOffset, scrollWidth + frame, title + 3 * menuFrame);
- moreNew := TRUE; { See "GetTLWindPortRect" }
- startBalloons := BalloonsOn;
- IF aMac2 THEN
- BEGIN
- currScreenDev := GetMainDevice;
- nextScreenDev := GetNextDevice(currScreenDev);
- END;
- SetUpMainMenus;
-
- System7Braggart;
-
- IF NOT DoNewWindow(mainWindowID, wMBARID, offset) THEN
- BEGIN { CanNOT find window resource. }
- DisposHandle(Handle(mBarList));
- HUnlock(Handle(windowStorage));
- DisposHandle(Handle(windowStorage));
- ExitToShell;
- END;
-
- MainEventLoop;
-
- ResetBalloons(startBalloons);
- ;
- PlaySound('Moof');
-
- ExitToShell;
-
-
-
- END. { Program }